package com.gjun.struts.action;

import java.util.Arrays;
import java.util.Date;

import com.gjun.struts.bean.GjunsystemRole;
import com.gjun.struts.resource.GjunRoleResourceIf;

public class SaveRoleAction {
    private String rolename;
    private String info;
    private String[] authority;  //[1,2,3,9,10,11]   
    // <input type="checkbox" name="authority" value="1"/>
    // <input type="checkbox" name="authority" value="2"/>
    
    private String result;
    
    private GjunRoleResourceIf systemRoleDAO;
    
    
    
    
	public GjunRoleResourceIf getSystemRoleDAO() {
		return systemRoleDAO;
	}
	public void setSystemRoleDAO(GjunRoleResourceIf systemRoleDAO) {
		this.systemRoleDAO = systemRoleDAO;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String[] getAuthority() {
		return authority;
	}
	public void setAuthority(String[] authority) {
		this.authority = authority;
	}
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	}
	public String getRolename() {
		return rolename;
	}
	public void setRolename(String rolename) {
		this.rolename = rolename;
	}
    
    
	public String execute(){
		//System.out.println(rolename+"  rolename");
		//System.out.println(info+"  info");
		//System.out.println(Arrays.toString(authority)+"  authority");
		
		boolean isHave = systemRoleDAO.loadRoleByName(rolename);
		if(isHave){
			result = "roleExist";
			return "success";
		}
		
		GjunsystemRole role = new GjunsystemRole();
		role.setInfo(info);
		role.setRegdate(new Date());
		role.setRolename(rolename);
		
		systemRoleDAO.saveRole(role,authority);
		result = "success";
		return "success";
	}
}
